<template>
	<view class="custom-tabs">
		<view class="tabs-container" :class="{ 'other': tabs.length < 4 }">
			<view 
				v-for="(tab, index) in tabs" 
				:key="index"
				class="tab-item"
				:class="{ 'active': currentTab === index }"
				@click="selectTab(index)"
			>
				<text class="tab-text">{{ tab.label }}</text>
				<view v-if="currentTab === index" class="tab-indicator"></view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'CustomTabs',
		props: {
			modelValue: {
				type: Number,
				default: 0
			},
			tabs: {
				type: Array,
				default: [
					{ label: '全部', value: 'all' },
					{ label: '待审方', value: 'pending' },
					{ label: '已通过', value: 'approved' },
					{ label: '已驳回', value: 'rejected' }
				]
			}
		},
		emits: ['change'],
		data() {
			return {
				currentTab: this.modelValue,
			}
		},
		watch: {
			modelValue(newVal) {
				this.currentTab = newVal
			}
		},
		methods: {
			selectTab(index) {
				this.currentTab = index
				this.$emit('change', {
					index,
					value: this.tabs[index].value,
					label: this.tabs[index].label
				})
			}
		}
	}
</script>

<style scoped>
	.custom-tabs {
		padding: 0;
	}

	.tabs-container {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.other {
		justify-content: space-around;
	}

	.tab-item {
		text-align: center;
		position: relative;
	}

	.tab-text {
		font-size: 28rpx;
		font-weight: 400;
    	padding: 0 10px 6px;
	}

	.tab-item:not(.active) .tab-text {
		color: #9E9E9E;
	}

	.tab-item.active .tab-text {
		color: #424242;
		font-weight: 500;
	}

	.tab-indicator {
		position: absolute;
    	bottom: -2rpx;
    	right: 12%;
		width: 16rpx;
		height: 16rpx;
		background: #1D77FF;
		border-radius: 50%;
		z-index: -1;
	}

	@keyframes fadeIn {
		from {
			opacity: 0;
			transform: translateX(-50%) scale(0.5);
		}
		to {
			opacity: 1;
			transform: translateX(-50%) scale(1);
		}
	}

	.tab-item:active {
		transform: scale(0.95);
	}
</style>
